'use strict'
export default {
    methods: {
        mixDateTransform(date, detail=true) {
            if (!date) {
                return '--'
            }
            if(typeof date === 'number' || typeof date === 'string'){
                date = new Date(date)
            }
            let y = this.zeroBu(date.getFullYear())// 年
            let m = this.zeroBu(date.getMonth() + 1)// 月
            let d = this.zeroBu(date.getDate())// 日
            let h = this.zeroBu(date.getHours())// 时
            let mm = this.zeroBu(date.getMinutes())// 分
            let s = this.zeroBu(date.getSeconds())// 秒
            if (detail) {
                return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s
            } else {
                return y + '-' + m + '-' + d
            }
        },

        mixDateTimestempMill(date, isStart) {
            if (!date) {
                return
            }
            if(typeof date === 'number' || typeof date === 'string'){
                date = new Date(date)
            }
            let y = this.zeroBu(date.getFullYear())// 年
            let m = this.zeroBu(date.getMonth() + 1)// 月
            let d = this.zeroBu(date.getDate())// 日
            if (isStart) {
                const startString = y + '-' + m + '-' + d + ' 00:00:01'
                return (new Date(startString)).getTime()
            } else {
                const endString = y + '-' + m + '-' + d + ' 23:59:59'
                return (new Date(endString)).getTime()
            }
        },

        zeroBu(n) {
            if (+n < 10) {
                return '0' + n
            } else {
                return n
            }
        },

        toast(content, type = 2) {
            switch (+type) {
                case 1:
                    this.$message({
                        showClose: true,
                        message: content || '--',
                        type: 'success'
                    })
                    return
                case 2:
                    this.$message({
                        showClose: true,
                        message: content || '--'
                    })
                    return
                case 3:
                    this.$message({
                        showClose: true,
                        message: content || '--',
                        type: 'warning'
                    })
                    return
                case 4:
                    this.$message({
                        showClose: true,
                        message: content || '--',
                        type: 'error'
                    })
                    return
            }
        }
        /** -----------------end----------------- */
    }
}
